//package com.healthtop.common;
//
//import org.aspectj.lang.annotation.*;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.transaction.annotation.Propagation;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.Date;
//
//@Aspect
////@Component
//public class ServiceExceptionAspect {
//
//    @Autowired
//    private ErrorLogService errorLogService;
//
//    @Autowired
//    private UserService userService;
//
//    /**
//     * @within(org.springframework.stereotype.Service)，拦截带有 @Service 注解的类的所有方法
//     * @annotation(org.springframework.web.bind.annotation.RequestMapping)，拦截带有@RquestMapping的注解方法
//     */
//    @Pointcut("@within(org.springframework.stereotype.Service)")
//    private void servicePointcut() {}
//
//    @AfterThrowing(pointcut = "servicePointcut()", throwing = "e")
//    @Transactional(propagation= Propagation.NOT_SUPPORTED)
//    public void afterThrowing(Throwable e) {
//        String message = getStackMsg(e);
////        ErrorLog errorLog = new ErrorLog();
////        errorLog.setErrorMessage(message);
////        errorLog.setCreateTime(new Date());
////        errorLogService.save(errorLog);
//    }
//
//    private static String getStackMsg(Throwable e) {
//        StringBuffer sb = new StringBuffer();
//        StackTraceElement[] stackArray = e.getStackTrace();
//        for (int i = 0; i < 2; i++) {
//            StackTraceElement element = stackArray[i];
//            sb.append(element.toString() + "\n");
//        }
//        return sb.toString();
//    }
//
//}
